package com.haiqi.modules.map.service;

import com.haiqi.common.persistence.dao.ReportLineInfoMapper;
import com.haiqi.common.persistence.entity.ReportLineInfo;
import com.haiqi.common.utils.UUIDGenerator;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by HaiQi on 2017-2-27.
 */
@Service
public class ReportLineInfoService {
    @Autowired
    private ReportLineInfoMapper reportLineInfoMapper;

    /**
     * 保存报告线信息
     * 如果报告线信息存在ID，则更新报告线信息；否则新增报告线信息
     * @param reportLineInfo 报告线信息
     * @return 如皋修改成功 返回TRUE，否则，返回false
     */
    public boolean save(ReportLineInfo reportLineInfo){
        boolean isSuccess=false;
        int result=0;
        if (StringUtils.isNotEmpty(reportLineInfo.getId())){
            result = reportLineInfoMapper.updateByPrimaryKey(reportLineInfo);
        }else{
            reportLineInfo.setId(UUIDGenerator.getUUID());
            result = reportLineInfoMapper.insert(reportLineInfo);
        }

        if (result>0){
            isSuccess=true;
        }

        return  isSuccess;
    }

    /**
     * 删除报告线信息
     * @param id 报告线ID
     * @return 如果删除成功，则返回true，否则返回False
     */
    public boolean delete(String id){
        boolean isSuccess = false;
        int result = 0;
        result = reportLineInfoMapper.deleteByPrimaryKey(id);
        if (result>0){
            isSuccess = true;
        }else{
            isSuccess = false;
        }
        return  isSuccess;
    }

    /**
     * 根据报告线ID更新报告线显示标记
     * @param showstate 报告线显示标记
     * @param id 报告线ID
     * @return 如果更新成功，返回TRUE，否则，返回False
     */
    public boolean updateStateById(String showstate,String id){
        boolean isSuccess = false;
        int result = 0;
        result = reportLineInfoMapper.updateStateById(showstate,id);
        if (result>0){
            isSuccess = true;
        }else{
            isSuccess = false;
        }
        return  isSuccess;
    }
    /**
     * 查询一个报告线信息
     * @param id 报告线ID
     * @return 返回一个报告线信息，或者返回Null
     */
    public ReportLineInfo getOneReportLineInfo(String id){
        ReportLineInfo reportLineInfo = null;
        reportLineInfo = reportLineInfoMapper.selectByPrimaryKey(id);
        return  reportLineInfo;
    }

    /**
     * 获取所有的报告线信息
     * @return 返回全部的报告线信息
     */
    public List<ReportLineInfo> findAll(){
        return  reportLineInfoMapper.selectAll();
    }

    /**
     * 根据报告线类型获取同一种报告线信息
     * @param linetype 报告线类型
     * @return 返回同一类型的报告线信息
     */
    public List<ReportLineInfo> findAllByType(String linetype){
        return reportLineInfoMapper.selectByType(linetype);
    }
}
